<?php
/**
 *  💡 免责声明：本软件不得用于商业用途，仅做学习交流
 *  ⚠️ 权利声明：本软件由版权人提供产品技术支持
 *  📅 项目编号：NX2025-0135
 */
namespace App\Admin\Controllers;

use App\Admin\Repositories\OrderBatch;
use Dcat\Admin\Form;
use Dcat\Admin\Grid;
use Dcat\Admin\Http\Controllers\AdminController;
use Dcat\Admin\Show;

class OrderBatchController extends AdminController
{
    /**
     * Make a grid builder.
     *
     * @return Grid
     */
    protected function grid()
    {
        return Grid::make(new OrderBatch(['user', 'session']), function (Grid $grid) {
            $grid->disableCreateButton();
            $grid->disableRefreshButton();
            $grid->disableViewButton();
            $grid->disableRowSelector();
            $grid->disableActions();
            $grid->model()->orderByDesc('id');
            $grid->column('id')->sortable();
            $grid->column('advance_card','支付类型')->display(function ($v) {
                if ($v > 0){
                    return '垫付卡支付';
                }
                return '余额支付';
            });

            $grid->column('user.telephone', '会员电话')->copyable();
            $grid->column('session.name', '场次名称');
            $grid->column('session.date', '场次日期');
            $grid->column('order_count', '批次下单数');
            $grid->column('cumulative_orders', '累计单数');
            $grid->column('success_count', '中单数');
            $grid->column('failure_count');
            $grid->column('payment_balance');
            $grid->column('payment_bean');
            $grid->column('balance_unit_price');
            $grid->column('bean_unit_price');
            $grid->column('reward_contribution');
            $grid->column('point_burning_reward','代金券燃烧奖励');
            $grid->column('bean_burning_reward');
            $grid->column('status')->using([
                0 => '拼团中',
                2 => '已结算'
            ]);
            $grid->column('created_at');
            $grid->column('updated_at')->sortable();

            $grid->filter(function (Grid\Filter $filter) {
                $filter->equal('id');
            });
        });
    }

    /**
     * Make a show builder.
     *
     * @param mixed $id
     *
     * @return Show
     */
    protected function detail($id)
    {
        return Show::make($id, new OrderBatch(), function (Show $show) {
            $show->field('id');
            $show->field('user_id');
            $show->field('session_id');
            $show->field('order_count');
            $show->field('cumulative_orders');
            $show->field('success_count');
            $show->field('failure_count');
            $show->field('payment_bean');
            $show->field('balance_unit_price');
            $show->field('bean_unit_price');
            $show->field('payment_balance');
            $show->field('reward_contribution');
            $show->field('point_burning_reward');
            $show->field('bean_burning_reward');
            $show->field('advance_card');
            $show->field('status');
            $show->field('created_at');
            $show->field('updated_at');
        });
    }

    /**
     * Make a form builder.
     *
     * @return Form
     */
    protected function form()
    {
        return Form::make(new OrderBatch(), function (Form $form) {
            $form->display('id');
            $form->text('user_id');
            $form->text('session_id');
            $form->text('order_count');
            $form->text('cumulative_orders');
            $form->text('success_count');
            $form->text('failure_count');
            $form->text('payment_bean');
            $form->text('balance_unit_price');
            $form->text('bean_unit_price');
            $form->text('payment_balance');
            $form->text('reward_contribution');
            $form->text('point_burning_reward');
            $form->text('bean_burning_reward');
            $form->text('advance_card');
            $form->text('status');

            $form->display('created_at');
            $form->display('updated_at');
        });
    }
}
